package thread.bank;

public class Bank {
	private double balance;
	private String account;
	private boolean isLeft;
	public Bank(){
		
	}
	public double getBalance() {
		return balance;
	}
	public void setBalance(double balance) {
		this.balance = balance;
	}
	public String getAccount() {
		return account;
	}
	public void setAccount(String account) {
		this.account = account;
	}
	public Bank(String a,double b){
		this.balance=b;
		this.account=a;
	}
	public synchronized void withdrawal(double dAmount) throws InterruptedException{
		if(!isLeft){
			wait();
		}
		if(this.balance>=dAmount){
			System.out.println(Thread.currentThread().getName()+"取款成功,取出"+dAmount+"元");
			this.balance-=dAmount;
			System.out.println("当前余额为"+this.balance+"元");
		}else{
			System.out.println("余额不足");
			isLeft=false;
			notifyAll();
		}
	}
	public synchronized void deposite(double dAmount) throws InterruptedException{
		if(isLeft){
			wait();
		}else{
			this.setBalance(this.getBalance()+dAmount);
			System.out.println(Thread.currentThread().getName()+",存款");
			isLeft=true;
			notifyAll();
		}
	}
}
